package com.itheima.mapper1;

import com.itheima.domain.ShoppingCart;
import com.itheima.domain.User;
import jdk.internal.dynalink.linker.LinkerServices;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * @author wuyiqiang
 * @2022/6/18 13:39
 */
@Mapper
public interface ShoppingCartMapper {

    /**
     * 查看购物车列表
     *
     * @return
     */
    @Select("select  * from shopping_cart")
    List<ShoppingCart> select();

    /**
     * 查看购物车中是否有该菜品或者套餐
     *
     * @param shoppingCart
     * @return
     */
    ShoppingCart selectDisOrSid(ShoppingCart shoppingCart);

    /**
     * 添加商品或者套餐
     *
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart values (#{id},#{name},#{userId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime},#{dishId})")
    void add(ShoppingCart shoppingCart);

    /**
     * 修改购物车信息
     *
     * @param shoppingCart1
     */
    @Update("update shopping_cart set number =#{number} where id=#{id}")
    void update(ShoppingCart shoppingCart1);

    /**
     * 清空购物车
     *
     * @param userId
     * @return
     */
    @Delete("delete from shopping_cart ")
    int delete(String userId);

    /**
     * 删除套餐或者菜品
     *
     * @return
     */
    int deleteById(ShoppingCart shoppingCart);

    /**
     * 根据当前用户id获取购物车信息
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> selectByUserId(String userId);
}
